package com.eling.elcms.cater.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;
/**
 * 菜单
 * @author Liuyp
 *
 */

@Entity
@Table(name = "cate_dishmenu")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "servicepoint:servicePoint")})
public class DishMenu extends BaseModel{
	
	private static final long serialVersionUID = -2719224357757152443L;
	
	@Id
	@In
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	private Long pkDishMenu;
	
	/** 菜品 */
	@ManyToMany
	@JoinTable(name = "cate_dishmenu_dish",
		joinColumns = {@JoinColumn(name = "pkDishMenu")},
		inverseJoinColumns = {@JoinColumn(name = "pkDish")})
	@IndexedEmbedded(depth = 1)
	private Set<Dish> dishes;
	
	/** 套餐*//*
	@ManyToMany
	@JoinTable(name = "cate_dishmenu_setmeal",
		joinColumns = {@JoinColumn(name = "pkDishMenu")},
		inverseJoinColumns = {@JoinColumn(name = "pkSetMeal")})
	@IndexedEmbedded
	private Set<SetMeal> setMeals;*/
	
	/** 日期*/
	@Column
	@Field
	@Between
	private Date menuDate;
	
	/** 服务点 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkServicePoint")
	private ServicePoint servicePoint;
	
	/** 菜单类型  */
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private DishMenuType dishMenuType;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum DishMenuType {
		Breakfast("早餐"),
		Lunch("午餐"), 
		Supper("晚餐");

		private String display;
		DishMenuType(String display) {
			this.display = display;
		}
		public String getDisplay() {
			return display;
		}
	}
	
	@Version
	private Integer version;
	
	public ServicePoint getServicePoint() {
		return servicePoint;
	}

	public void setServicePoint(ServicePoint servicePoint) {
		this.servicePoint = servicePoint;
	}

	public Long getPkDishMenu() {
		return pkDishMenu;
	}

	public void setPkDishMenu(Long pkDishMenu) {
		this.pkDishMenu = pkDishMenu;
	}

	public Set<Dish> getDishes() {
		return dishes;
	}

	public void setDishes(Set<Dish> dishes) {
		this.dishes = dishes;
	}

	public Date getMenuDate() {
		return menuDate;
	}

	public void setMenuDate(Date menuDate) {
		this.menuDate = menuDate;
	}

	public DishMenuType getDishMenuType() {
		return dishMenuType;
	}

	public void setDishMenuType(DishMenuType dishMenuType) {
		this.dishMenuType = dishMenuType;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

}
